<!DOCTYPE html>
<html>
<head>
<title>商盟统统付标准收银台接口</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
date_default_timezone_set("Asia/Shanghai");
$timestamp = date('YmdHis');

$url = 'https://test.sumpay.cn/entrance/gateway.htm';
$domain = $_POST["domain"];
$service = 'cn.sumpay.genero.trade.batch.agent.pay';
$withdraw_list = $_POST["withdraw_list"];
// $withdraw_list = strtr($withdraw_list, '\'', '\"');
$parameters = [
    'app_id' => $_POST["mer_no"],
    'terminal_type' => $_POST["terminal_type"],
    'version' => '1.0',
    'format' => 'JSON',
    'service' => $service,
    'timestamp' => $timestamp,
    'mer_no' => $_POST["mer_no"],
    'batch_num' => $_POST["batch_num"],
    'batch_amount' => $_POST["batch_amount"],
    'need_notify' => $_POST["need_notify"],
    'withdraw_list' => $withdraw_list
];
$sub_mer_no = $_POST["sub_mer_no"];
$notify_url = $_POST["notify_url"];
$mer_batch_no = $_POST["mer_batch_no"];

if ($sub_mer_no && "" != $sub_mer_no) {
    $parameters['sub_mer_no'] = $sub_mer_no;
}
if ($mer_batch_no && "" != $mer_batch_no) {
    $parameters['mer_batch_no'] = $mer_batch_no;
}
if ($notify_url && "" != $notify_url) {
    $parameters['notify_url'] = $notify_url;
}
$encrypted_fields = array(
    "account_no",
    "realname",
    "id_no"
);
$charset_change_fields = array(
    "terminal_info",
    "realname",
    "open_city",
    "bank_branch",
    "pay_comments",
    "remark"
);
$special_fields = array(
    "terminal_info",
    "withdraw_list",
    "notify_url",
    "open_city",
    "bank_branch",
    "pay_comments",
    "remark"
);

$json_array_fields = array(
    "withdraw_list"
);

$defaultCharset = 'UTF-8';

include '../tools/SumpayService.php';
$res = execute($url, 'UTF-8', $parameters, "../cer/yixuntiankong.pfx", "sumpay", "../cer/dev_pub.pem", $domain, $charset_change_fields, $encrypted_fields, $special_fields, $json_array_fields, $defaultCharset);
if ($res['resp_code'] == '000000') {
    // 表示处理成功，可以处理后续业务
    if (substr($service, 0, 20) == 'fosun.sumpay.cashier') {
        $returnUrl = $res['redirect_url'];
        echo <<< HTML
<form hidden=true method=post action=$returnUrl>
<input hidden=true type=submit value=ok>
</form>
<script>
document.forms[0].submit();
</script>
HTML;
    } else {
        // 这步只是展示成功的响应，具体业务商户自己处理
        echo  json_encode($res);
    }
} else {
    echo  json_encode($res);
}

?>

</body>
</html>
